﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Configuration;

namespace com.aspnet
{
    /// <summary>
    /// 可以通过两种方式来使用自定义的配置节
    /// 
    /// 编程模式：
    /// 
    /// 这种模式需要针对每一个配置节中的 XML 属性 (attribute) 定义一个类的属性 (property) 用来获取或者设置
    /// 然后，这个类的属性 (property) 需要加入到一个内部的属性包中
    /// 
    /// 定义模式：
    /// 
    /// 这是一个简单的模式，允许通过标签 (attribute) 装饰过的类的属性 (property) 来定义节的属性 (attribute)，
    /// 
    /// </summary>
    public sealed class OnlineUserConfigSection : ConfigurationSection
    {
        [ConfigurationProperty("enabled", DefaultValue = false)]
        public bool Enabled
        {
            get
            {
                return (bool) this["enabled"];
            }
        }

        [ConfigurationProperty("period",
            DefaultValue = "10000",
            IsRequired = true,
            IsKey = false)]
        [LongValidator(MinValue = 1000, MaxValue = 1000000, ExcludeRange = false)]
        public long Period
        {
            get
            {
                return (long)this["period"];
            }
        }

        [ConfigurationProperty("dueTime",
            DefaultValue = "60000",
            IsRequired = true,
            IsKey = false)]
        [LongValidator(MinValue = 1000, MaxValue = 1000000, ExcludeRange = false)]
        public long DueTime
        {
            get
            {
                return (long)this["dueTime"];
            }
        }

        [ConfigurationProperty("timeout",
            DefaultValue = "10000",
            IsRequired = true,
            IsKey = false)]
        [IntegerValidator(MinValue = 1000, MaxValue = 1000000, ExcludeRange = false)]
        public int Timeout
        {
            get
            {
                return ((int)this["timeout"]) / 1000;
            }
        }
    }
}
